package com.dailyblue.java.cloud.security.service.impl;

import com.dailyblue.java.cloud.security.bean.User;
import com.dailyblue.java.cloud.security.bean.UserLoginDetails;
import com.dailyblue.java.cloud.security.service.UserService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if (!"admin".equals(username)) {
            throw new UsernameNotFoundException("用户不存在！");
        }
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        User user = new User(1, username, passwordEncoder.encode("123456"));
        UserLoginDetails uld = new UserLoginDetails(user);
        return uld;
    }
}
